[PyTorch] Support user-defined op fusions#2597
Merged
timmoon10 merged 12 commits intoNVIDIA:mainfrom Jan 25, 2026
Merged
Conversation
Refactor fusion functions to remove index bookkeeping. Refactor fused ops to use consistent operation order. Signed-off-by: Tim Moon <tmoon@nvidia.com>
Signed-off-by: Tim Moon <tmoon@nvidia.com>
for more information, see https://pre-commit.ci
This comment was marked as outdated.
This comment was marked as outdated.
Contributor
Greptile SummaryThis PR adds support for user-defined operation fusions by introducing Key Changes:
Impact: Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant RegisterAPI as register_forward_fusion/<br/>register_backward_fusion
participant OperationFuser
participant FusionFunc as Custom Fusion Function
participant FusedOp as Fused Operation
User->>RegisterAPI: register custom fusion function
RegisterAPI->>OperationFuser: append to forward_fusion_functions<br/>or backward_fusion_functions
Note over User,FusedOp: During model execution
User->>OperationFuser: __call__(input, ...)
OperationFuser->>OperationFuser: maybe_fuse_ops()
loop For each fusion function
OperationFuser->>FusionFunc: func(ops, recipe=recipe)
FusionFunc->>FusionFunc: scan ops with sliding window
alt Pattern matches
FusionFunc->>FusedOp: create fused op
FusedOp-->>FusionFunc: fused operation
else No match
FusionFunc->>FusionFunc: shift window
end
FusionFunc-->>OperationFuser: updated ops list
end
OperationFuser->>OperationFuser: store _forward_ops and _backward_ops
Note over OperationFuser,FusedOp: Forward pass
loop For each forward op
OperationFuser->>FusedOp: fuser_forward(ctxs, input, ...)
FusedOp->>FusedOp: execute fused computation
FusedOp->>FusedOp: save state to contexts
FusedOp-->>OperationFuser: output
end
Note over OperationFuser,FusedOp: Backward pass
loop For each backward op (reversed)
OperationFuser->>FusedOp: fuser_backward(ctxs, grad_output, ...)
FusedOp->>FusedOp: restore from contexts
FusedOp->>FusedOp: execute fused backward
FusedOp-->>OperationFuser: grad_input, grad_params
end
OperationFuser-->>User: outputs and gradients
|
Signed-off-by: Tim Moon <tmoon@nvidia.com>
Signed-off-by: Tim Moon <tmoon@nvidia.com>
for more information, see https://pre-commit.ci
This comment was marked as outdated.
This comment was marked as outdated.
Signed-off-by: Tim Moon <tmoon@nvidia.com>
Signed-off-by: Tim Moon <tmoon@nvidia.com>
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This was referenced Jan 21, 2026
Signed-off-by: Tim Moon <tmoon@nvidia.com>
Signed-off-by: Tim Moon <tmoon@nvidia.com>
This comment was marked as outdated.
This comment was marked as outdated.
1 similar comment
Collaborator
Author
|
/te-ci pytorch L1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR adds the
register_forward_fusionandregister_backward_fusionfunctions to the op fuser API, allowing users to register custom fusions.Type of change
Changes
Checklist: